﻿using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Projectiles.Sets.Sleep
{
    public class DreamShuriken : ModProjectile
    {
        public override string Texture => "HardcoreGame/Content/Items/Weapons/Sets/Sleep/DreamShuriken";
        public override void SetDefaults()
        {
            Projectile.width = 22;
            Projectile.height = 22;
            Projectile.aiStyle = 0;
            Projectile.friendly = true;
            Projectile.DamageType = DamageClass.Ranged;
            Projectile.penetrate = 1;
        }
        public override void AI()
        {
            int Dust1 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y + 2f), Projectile.width + 1, Projectile.height + 1, DustID.WhiteTorch, Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 120, default, 2f);
            Main.dust[Dust1].noGravity = true;
            Projectile.rotation += 1f;
            Projectile.velocity.Y += 0.1f;
        }
        public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
        {
            int Dust1 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y + 2f), Projectile.width + 1, Projectile.height + 1, DustID.WhiteTorch, Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 120, default, 5f);
            Main.dust[Dust1].noGravity = true;
            if (Main.rand.NextBool(10) && !target.HasBuff<Buffs.Sleep>())
            {
                target.AddBuff(ModContent.BuffType<Buffs.Sleep>(), 300);
            }
        }
        public override void OnKill(int timeLeft)
        {
            SoundEngine.PlaySound(SoundID.Item1, Projectile.position);
            for (int i = 0; i < 10; i++)
            {
                int Dust1 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y + 2f), Projectile.width + 1, Projectile.height + 1, DustID.WhiteTorch, Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 120, default, 3f);
                Main.dust[Dust1].noGravity = true;
            }
        }
    }
}
